#include "solve_dfs.h"


namespace solve_dfs_ns{
    int pd=0;
    int wkx[4]={0,-1,0,1};
    int wky[4]={-1,0,1,0};
    int step;
    bool judge[1000][1000];
}

using namespace solve_dfs_ns;
using std::cin ;
using std::cout;
using std::endl;

Point ans[10000000];


void print_dfs_ans()
{
    cout<<endl;
    if(!pd)
    {
        cout<<"No Answer!"<<endl;
        return;
    }
    int num=1,tempx=1,tempy=1;
    cout<<"("<<ans[0].x<<","<<ans[0].y<<")"<<endl;
    for(int i=1;i<step;i++) {
        cout<<"("<<ans[i].x<<","<<ans[i].y;
        if(ans[i].x==tempx&&ans[i].y==tempy+1)  cout<<","<<"left"<<")"<<endl;
        if(ans[i].x==tempx&&ans[i].y==tempy-1)  cout<<","<<"right"<<")"<<endl;
        if(ans[i].x==tempx+1&&ans[i].y==tempy)  cout<<","<<"up"<<")"<<endl;
        if(ans[i].x==tempx-1&&ans[i].y==tempy)  cout<<","<<"down"<<")"<<endl;
        num++;
        tempx=ans[i].x,tempy=ans[i].y;
    }
    cout<<"("<<endpoint.x<<","<<endpoint.y<<")"<<endl;
}

void solve_dfs(int x, int y)
{
    if(pd) return;
    if(x==endpoint.x&&y==endpoint.y)
    {
        cout<<endl; cout<<endl;
        pd=1;
        return;
    }
    for(int i=0;i<=3;i++)
    {
        dfsnum++;
        int xx = x+wkx[i];
        int yy = y+wky[i];
        if((xx>=0)&&(yy>=0)&&(map[xx][yy]==0)&&(judge[xx][yy]==0))
        {
            judge[x][y]=1;
            ans[step].x=x;
            ans[step].y=y;
            step++;
            Set_Grapics(y*2,x,12);cout<<"*";
            solve_dfs(xx,yy);if(pd) break;
            judge[x][y]=0;
            Set_Grapics(y*2,x,12);cout<<"  ";
            step--;
        }
    }

}